1 00:00:00,540 --> 00:00:04,620 Today, we're going to start adding points to our leaderboard and we're going to use the coin to do 2 00:00:04,620 --> 00:00:05,140 that. 3 00:00:05,160 --> 00:00:10,110 We'll also add points when we do NPC kills once we start making our weapons. 4 00:00:10,110 --> 00:00:12,360 So let's go ahead and get started with that. 5 00:00:13,210 --> 00:00:18,550 Let's go ahead and turn off our game stop and then we'll go to server storage. 6 00:00:18,580 --> 00:00:20,540 Open that up if it's closed. 7 00:00:20,560 --> 00:00:24,010 Check to see that you got a coin, because that's what we're going to spawn and we're going to spawn 8 00:00:24,010 --> 00:00:26,080 it from server store to make sure it's here. 9 00:00:26,110 --> 00:00:26,350 All right. 10 00:00:26,350 --> 00:00:27,810 We did that earlier in the course. 11 00:00:27,820 --> 00:00:33,340 So now let's go up to our workspace and we're going to add a folder. 12 00:00:34,260 --> 00:00:37,720 And we're going to call that coins because we're going to put the coins in the folder much like we did 13 00:00:37,740 --> 00:00:40,050 the health and the mines and all that other stuff. 14 00:00:40,500 --> 00:00:41,570 Coins. 15 00:00:41,580 --> 00:00:42,380 Cool. 16 00:00:42,390 --> 00:00:46,190 Now go down to server scripts service. 17 00:00:46,200 --> 00:00:50,700 If you don't have it open, I have it open, but I'll show you where to find it again and we'll get 18 00:00:50,700 --> 00:00:52,580 session utils. 19 00:00:52,590 --> 00:00:56,730 Scroll up to the top and we're going to put a. 20 00:00:57,730 --> 00:00:59,130 A variable for our folder. 21 00:00:59,140 --> 00:01:03,580 Say local coin folder. 22 00:01:04,180 --> 00:01:07,240 Workspace coins. 23 00:01:07,240 --> 00:01:09,190 That's where our coins are going to go. 24 00:01:09,220 --> 00:01:13,090 Now the health and the coins are going to be very similar. 25 00:01:13,090 --> 00:01:17,980 So you could be thinking, Hey, I could just modify this health to be a little more general. 26 00:01:17,980 --> 00:01:19,200 Save some code. 27 00:01:19,210 --> 00:01:20,580 That'd be a good idea. 28 00:01:20,590 --> 00:01:22,810 You could do that as an exercise. 29 00:01:23,230 --> 00:01:25,180 I'm just going to copy and paste it. 30 00:01:26,340 --> 00:01:26,620 Right. 31 00:01:26,620 --> 00:01:28,260 That's for the innovation sprint, right. 32 00:01:28,300 --> 00:01:29,920 Refactoring your code. 33 00:01:29,920 --> 00:01:30,280 All right. 34 00:01:30,280 --> 00:01:34,300 So I read, I read, pasted our health, our place, health. 35 00:01:34,300 --> 00:01:36,640 Let's change that to place coin. 36 00:01:38,940 --> 00:01:39,720 Coins. 37 00:01:39,720 --> 00:01:41,460 Let's do with an SE. 38 00:01:41,490 --> 00:01:44,490 We're going to need the number of coins. 39 00:01:47,020 --> 00:01:51,550 We're not going to need a center point because we're going to span the whole terrain. 40 00:01:52,300 --> 00:01:53,830 But we will need the distance. 41 00:01:53,830 --> 00:01:57,640 The distance is going to be the size of the terrain because you might want to have this on different 42 00:01:57,640 --> 00:01:58,690 size terrains. 43 00:01:59,020 --> 00:01:59,470 All right. 44 00:01:59,470 --> 00:02:00,810 Now to health. 45 00:02:00,820 --> 00:02:06,280 Well, we're going to go ahead and get a template coin that was for template health. 46 00:02:07,380 --> 00:02:08,430 In server storage. 47 00:02:08,430 --> 00:02:10,410 If you have your coin there, you should see coin. 48 00:02:10,440 --> 00:02:11,400 There we go. 49 00:02:12,210 --> 00:02:13,890 Make sure you change this. 50 00:02:13,890 --> 00:02:15,670 This is your coin folder. 51 00:02:15,690 --> 00:02:18,720 The number of elements in the coin folder. 52 00:02:19,260 --> 00:02:19,890 There we go. 53 00:02:19,890 --> 00:02:22,080 So we're going to get the coin folders, children. 54 00:02:22,080 --> 00:02:24,510 And then this is going to give us the number of those children. 55 00:02:25,540 --> 00:02:30,310 Elements, coins, a number of coins, and then we'll get our number of coins here. 56 00:02:30,310 --> 00:02:35,320 If the count is insufficient, we are going to spawn more coins. 57 00:02:35,920 --> 00:02:37,360 This looks good right here. 58 00:02:37,360 --> 00:02:38,170 This is our distance. 59 00:02:38,170 --> 00:02:40,930 We're going to get random x, a random z. 60 00:02:41,020 --> 00:02:46,270 We're going to use our ray casting to get the height because we might have unusual terrain. 61 00:02:46,510 --> 00:02:49,270 We're not going to use the center point. 62 00:02:49,270 --> 00:02:53,050 So go ahead and get rid of that center point X plus. 63 00:02:53,050 --> 00:02:54,970 Just put the x rand in there. 64 00:02:55,690 --> 00:03:01,780 And this is going to default to the zero part of the world on the X and the Z to be the center point. 65 00:03:02,740 --> 00:03:06,310 And that looks good to health. 66 00:03:06,700 --> 00:03:09,730 Well, we're going to make a clone of our HT coin. 67 00:03:10,450 --> 00:03:11,230 Cool. 68 00:03:11,320 --> 00:03:12,460 This will be Coyne. 69 00:03:14,390 --> 00:03:16,400 Let's go ahead and copy that coin. 70 00:03:17,120 --> 00:03:22,880 Paste that here and do not forget this or you're going to crash your system because you're going to 71 00:03:22,910 --> 00:03:28,190 you're going to be counting from your coin folder, not your health folder. 72 00:03:29,090 --> 00:03:34,040 So keep making coins If you're putting them in your health folder, this is going to crash because we're 73 00:03:34,040 --> 00:03:39,710 never going to hit our number of coins and you're going to have too many resources going into your coins 74 00:03:40,010 --> 00:03:42,200 and put a coin position. 75 00:03:43,530 --> 00:03:45,360 Time to live in the coin. 76 00:03:46,510 --> 00:03:47,140 We make that. 77 00:03:47,940 --> 00:03:48,750 Yeah, that's good. 78 00:03:48,780 --> 00:03:49,770 5 minutes. 79 00:03:50,770 --> 00:03:51,940 And the count. 80 00:03:52,920 --> 00:03:57,750 While the health isn't going to be as many as the coin say, make sure you get that one right to coin 81 00:03:57,750 --> 00:03:58,530 folder. 82 00:03:59,670 --> 00:04:00,180 All right. 83 00:04:00,180 --> 00:04:01,500 Do we miss anything? 84 00:04:02,010 --> 00:04:03,830 This gets me all the time. 85 00:04:03,840 --> 00:04:05,550 You really shouldn't copy and paste. 86 00:04:05,550 --> 00:04:06,720 But I do it all the time. 87 00:04:06,720 --> 00:04:07,890 Everybody does, right? 88 00:04:08,860 --> 00:04:09,990 That's looking good. 89 00:04:09,990 --> 00:04:13,100 Now we're going to call this place coins. 90 00:04:13,110 --> 00:04:19,380 We can copy this so we don't forget Control C and now we'll go to our wave loop. 91 00:04:20,240 --> 00:04:21,080 Here we go. 92 00:04:21,080 --> 00:04:23,000 And we're going to need a couple of variables. 93 00:04:23,000 --> 00:04:30,830 So we have local number of coins and let's make a bunch of them. 94 00:04:30,830 --> 00:04:33,050 Let's make like 1000 coins. 95 00:04:34,630 --> 00:04:35,310 Cool. 96 00:04:35,320 --> 00:04:39,610 And then we can do distance. 97 00:04:40,800 --> 00:04:47,520 From coin center, and that's like the center of the world, right? 98 00:04:48,090 --> 00:04:55,710 So the distance outward from our coin center area, and we're going to make that 1024 because our terrain 99 00:04:55,710 --> 00:04:59,850 is 2048 by 2048 zero being in the center. 100 00:04:59,850 --> 00:05:02,400 So we can go plus or -1024. 101 00:05:03,090 --> 00:05:04,380 Cool. 102 00:05:04,950 --> 00:05:06,000 Let's go down here. 103 00:05:07,440 --> 00:05:09,120 Utils. 104 00:05:09,510 --> 00:05:13,530 Place coins so we didn't have to copy it. 105 00:05:13,530 --> 00:05:14,710 It gave it to us. 106 00:05:14,730 --> 00:05:17,430 And then we'll have a number of coins. 107 00:05:17,700 --> 00:05:19,380 And then the dist. 108 00:05:19,830 --> 00:05:24,960 Oh, the distance is the distance from coin center. 109 00:05:26,340 --> 00:05:28,830 And I put a parentheses there. 110 00:05:29,690 --> 00:05:30,450 That's looking good. 111 00:05:30,470 --> 00:05:31,970 Let's go ahead and check it out. 112 00:05:35,160 --> 00:05:36,300 Hit my play button. 113 00:05:37,770 --> 00:05:38,820 Where in the world? 114 00:05:39,120 --> 00:05:40,920 And let's check for errors. 115 00:05:40,920 --> 00:05:41,940 Output. 116 00:05:41,940 --> 00:05:42,960 No errors. 117 00:05:42,960 --> 00:05:44,280 That's looking good. 118 00:05:45,530 --> 00:05:46,910 There are some coins. 119 00:05:48,350 --> 00:05:48,740 All right. 120 00:05:48,740 --> 00:05:53,240 We don't have points yet, but we can get the coins and they disappear. 121 00:05:55,100 --> 00:05:56,000 Looking good. 122 00:05:56,900 --> 00:05:58,580 Let's check our workspace. 123 00:05:58,820 --> 00:06:00,980 Make sure the coins are going in there. 124 00:06:01,310 --> 00:06:03,190 Yeah, it's going to be like 1000 of them. 125 00:06:03,200 --> 00:06:08,030 That may have been overkill, but you can adjust that number however you want. 126 00:06:08,060 --> 00:06:08,630 I thought. 127 00:06:08,630 --> 00:06:10,700 I thought lots of coins would be cool. 128 00:06:12,980 --> 00:06:13,460 All right. 129 00:06:13,460 --> 00:06:18,980 Let's go ahead and add points to our coins using the leaderboard. 130 00:06:20,830 --> 00:06:25,630 All right, let's go to our server storage and then the coin in the server storage. 131 00:06:25,630 --> 00:06:28,390 Let's click on the collect script. 132 00:06:28,780 --> 00:06:29,800 Bring it on up. 133 00:06:30,190 --> 00:06:30,520 All right. 134 00:06:30,520 --> 00:06:33,610 So this is what we this is our touched event, right? 135 00:06:33,610 --> 00:06:39,430 So the coin touched event is connected to on collect on collect is fired when somebody touches it, 136 00:06:39,430 --> 00:06:43,760 when a character touches it, we check to see if there's a humanoid, if there is a humanoid to be given 137 00:06:43,760 --> 00:06:44,500 an award. 138 00:06:44,500 --> 00:06:50,500 We want to make sure that it's just players were giving the award to and now we're going to put points 139 00:06:50,500 --> 00:06:51,900 on the player's leaderboard. 140 00:06:51,910 --> 00:06:58,120 So the first thing we need to do is get the players service so we can get the player and then get the 141 00:06:58,120 --> 00:06:58,930 leaderboard. 142 00:06:59,140 --> 00:07:03,070 And I'm going to say game get service players. 143 00:07:03,070 --> 00:07:06,400 Now we have the player service and that variable right there. 144 00:07:06,550 --> 00:07:08,140 So we get to here. 145 00:07:08,140 --> 00:07:12,340 Let's say we got here, there's a humanoid, so it's a character of some type. 146 00:07:12,340 --> 00:07:16,900 It could be a zombie, it could be a player, but there's a character associated because we have a humanoid. 147 00:07:17,320 --> 00:07:22,750 Let's check, let's say local player. 148 00:07:22,750 --> 00:07:30,040 We're going to check for a player and we're going to do that by getting the player's service get player 149 00:07:30,040 --> 00:07:31,000 from character. 150 00:07:31,000 --> 00:07:38,290 Well, if Humanoid exists, their other part parent is definitely a character, just might not be a 151 00:07:38,290 --> 00:07:39,070 player. 152 00:07:39,070 --> 00:07:47,860 So then we'll say if player, then do all our cool stuff and put an end down here at the bottom and 153 00:07:47,860 --> 00:07:51,420 then we'll go to format selection, format document. 154 00:07:51,430 --> 00:07:52,720 Now it looks good. 155 00:07:53,110 --> 00:07:53,530 All right. 156 00:07:53,530 --> 00:07:56,710 So if we get here, we know we have a player. 157 00:07:56,710 --> 00:07:57,760 What are we going to do? 158 00:07:57,790 --> 00:08:00,550 We want to try and get points off the player's leaderboard. 159 00:08:00,550 --> 00:08:02,440 All the players have a leaderboard. 160 00:08:02,770 --> 00:08:04,030 We did that earlier. 161 00:08:04,030 --> 00:08:06,790 Oh, I do that every time points. 162 00:08:07,450 --> 00:08:11,560 And we've got the player and then the player has the leader stats. 163 00:08:11,560 --> 00:08:13,090 Remember, we call that leader stats. 164 00:08:13,120 --> 00:08:18,070 Got to call it leader stats and then the leader stats have points. 165 00:08:18,610 --> 00:08:22,390 I use the bracket notation points. 166 00:08:22,390 --> 00:08:27,640 So the name of the metric, the thing that you're going to see on the screen for the leaderboard. 167 00:08:27,820 --> 00:08:33,550 All right, now we want to increase our points so we get the points, points that are an value. 168 00:08:33,550 --> 00:08:35,650 So you have to do that value thing. 169 00:08:35,650 --> 00:08:38,170 Then we're going to do a plus equals ten. 170 00:08:38,170 --> 00:08:40,750 So we're going to take the old value and add ten to it. 171 00:08:40,750 --> 00:08:41,380 That's a plus. 172 00:08:41,380 --> 00:08:43,600 Equals means I should do it. 173 00:08:43,600 --> 00:08:45,220 Let's go ahead and give it a try. 174 00:08:45,460 --> 00:08:46,810 Hit the play button. 175 00:08:49,300 --> 00:08:51,670 Let's check for Iyer's view. 176 00:08:51,700 --> 00:08:52,810 Output. 177 00:08:52,810 --> 00:08:53,940 Looking good. 178 00:08:53,950 --> 00:08:58,480 No Ayers coins should be popping up at any second. 179 00:08:59,470 --> 00:09:00,340 There's a coin. 180 00:09:01,090 --> 00:09:02,320 So get our points. 181 00:09:03,280 --> 00:09:03,860 Booyah. 182 00:09:03,880 --> 00:09:06,160 We got ten points and we can run real fast. 183 00:09:06,860 --> 00:09:07,850 We could already do that. 184 00:09:07,970 --> 00:09:08,900 I missed the point. 185 00:09:08,900 --> 00:09:09,620 Or missed the coin. 186 00:09:10,430 --> 00:09:11,240 Cool. 187 00:09:11,660 --> 00:09:12,650 That's looking good. 188 00:09:13,310 --> 00:09:14,330 They were good to go. 189 00:09:14,330 --> 00:09:18,140 And the next video, what I'm going to do is let me turn that off. 190 00:09:18,380 --> 00:09:25,190 And the next video I'm going to do is add a sound and then have a little gooey, a little gooey. 191 00:09:25,220 --> 00:09:28,880 Go up saying that you got awarded 1010 gold.